package com.xiang.api.config.MyConfig;

import com.xiang.api.config.MyConfig.Open.Open;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Component
@EnableConfigurationProperties
@EnableTransactionManagement
@PropertySource("classpath:application.yml")
@ConfigurationProperties(prefix = "my-config")
public class MyConfig {

  @Autowired
  public Sql sql;

  @NestedConfigurationProperty
  public Open open;

  @Autowired
  public Login login;

  @Autowired
  public WebSocket webSocket;

  @Value("${spring.datasource.dynamic.datasource.master.url}")
  private String url;

  MyConfig() {
    // Sql s = new Sql();
    // spring.datasource.url
    // jdbc:mysql://localhost:3306/cme?useSSL=false&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
    // this.setUrl();
    // System.out.println(sql);

  }

  public void setSql(Sql sql) {
    System.out.println(2);
    System.out.println(sql);
    this.sql = sql;
  }

  public Sql sql() {
    return sql;
  }

  public void setOpen(Open open) {
    this.open = open;
  }

  public Open getOpen() {
    return open;
  }

  public void setLogin(Login login) {
    this.login = login == null ? new Login() : login;
  }

  public Login getLogin() {
    return login;
  }

  /**
   * @param webSocket the webSocket to set
   */
  public void setWebSocket(WebSocket webSocket) {
    this.webSocket = webSocket;
  }

  /**
   * @return the webSocket
   */
  public WebSocket getWebSocket() {
    return webSocket;
  }
  @Override
  public String toString() {
    return super.toString();
  }

}
